/*
 * RoofUI.java
 *
 * Created on 09-Nov-2010, 21:29:04
 */

package camp.tags;

import campskeleton.CampSkeleton;
import utils.WeakListener.Changed;

/**
 *
 * @author twak
 */
public class RoofUI extends javax.swing.JPanel {

    RoofTag roof;
    Changed rebuildFeatureList;

    /** Creates new form RoofUI */
    public RoofUI() {
        initComponents();
    }

    RoofUI(RoofTag roof, Changed rebuildFeatureList) {
        this.roof = roof;
        this.rebuildFeatureList = rebuildFeatureList;
        initComponents();
        widthScroll.setValue( (int) ( roof.width * widthScroll.getMaximum() ));
        heightScroll.setValue( (int) ( roof.height * heightScroll.getMaximum() ));
        jitterScroll.setValue( (int) ( roof.jitter * jitterScroll.getMaximum() ));
        staggerCheckBox.setSelected(roof.stagger);
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        staggerCheckBox = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        widthScroll = new javax.swing.JScrollBar();
        jLabel2 = new javax.swing.JLabel();
        jitterScroll = new javax.swing.JScrollBar();
        heightScroll = new javax.swing.JScrollBar();
        jLabel3 = new javax.swing.JLabel();

        staggerCheckBox.setText("stagger");
        staggerCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                staggerCheckBoxActionPerformed(evt);
            }
        });

        jLabel1.setText("width:");

        widthScroll.setMaximum(1000);
        widthScroll.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
        widthScroll.addAdjustmentListener(new java.awt.event.AdjustmentListener() {
            public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {
                widthScrollAdjustmentValueChanged(evt);
            }
        });

        jLabel2.setText("jitter:");

        jitterScroll.setMaximum(1000);
        jitterScroll.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
        jitterScroll.addAdjustmentListener(new java.awt.event.AdjustmentListener() {
            public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {
                jitterScrollAdjustmentValueChanged(evt);
            }
        });

        heightScroll.setMaximum(1000);
        heightScroll.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
        heightScroll.addAdjustmentListener(new java.awt.event.AdjustmentListener() {
            public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {
                heightScrollAdjustmentValueChanged(evt);
            }
        });

        jLabel3.setText("height:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(heightScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
                            .addComponent(widthScroll, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
                        .addGap(22, 22, 22)
                        .addComponent(jitterScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(widthScroll, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(heightScroll, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jitterScroll, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addContainerGap(48, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void widthScrollAdjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {//GEN-FIRST:event_widthScrollAdjustmentValueChanged
        roof.width = widthScroll.getValue() / (double) widthScroll.getMaximum();
        CampSkeleton.instance.somethingChanged();
        rebuildFeatureList.changed();
    }//GEN-LAST:event_widthScrollAdjustmentValueChanged

    private void jitterScrollAdjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {//GEN-FIRST:event_jitterScrollAdjustmentValueChanged
        roof.jitter = jitterScroll.getValue() / (double) jitterScroll.getMaximum();
        CampSkeleton.instance.somethingChanged();
    }//GEN-LAST:event_jitterScrollAdjustmentValueChanged

    private void heightScrollAdjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {//GEN-FIRST:event_heightScrollAdjustmentValueChanged
        roof.height = heightScroll.getValue() / (double) heightScroll.getMaximum();
        CampSkeleton.instance.somethingChanged();
        rebuildFeatureList.changed();
    }//GEN-LAST:event_heightScrollAdjustmentValueChanged

    private void staggerCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_staggerCheckBoxActionPerformed
        roof.stagger = staggerCheckBox.isSelected();
        CampSkeleton.instance.somethingChanged();
}//GEN-LAST:event_staggerCheckBoxActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollBar heightScroll;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollBar jitterScroll;
    private javax.swing.JCheckBox staggerCheckBox;
    private javax.swing.JScrollBar widthScroll;
    // End of variables declaration//GEN-END:variables

}
